
using System;
using System.Data;
using System.Text;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using PuntoMascotasWeb.BackEnd.BE;

namespace PuntoMascotasWeb.BackEnd.DAC
{
  /// <summary>
  /// TableDataGateway para Mascotas.
  /// </summary>
  /// <Date>2013-05-05T15:02:35</Date>
  /// <Author>Mx23</Author>
  public class MascotasDAC
  {
    /// <summary>
    /// Insert
    /// </summary>
    /// <param name="pMascotasBE">MascotasBE</param>
    /// <returns>void</returns>
    /// <Date>2013-05-05T15:02:35</Date>
    /// <Author>Mx23</Author>
    public static void Insert(MascotasBE pMascotasBE)
    {
      Database wDataBase = null;
      DbCommand wCmd = null;

      try
      {
        wDataBase = DatabaseFactory.CreateDatabase("cnnPuntoMascotasWeb");
        wCmd = wDataBase.GetStoredProcCommand("Mascotas_i");

        /// Id
        wDataBase.AddOutParameter(wCmd, "Id", System.Data.DbType.Int32, 4);
        /// Nombre
        wDataBase.AddInParameter(wCmd, "Nombre", System.Data.DbType.String, pMascotasBE.Nombre);
        /// IdRaza
        wDataBase.AddInParameter(wCmd, "IdRaza", System.Data.DbType.Int32, pMascotasBE.IdRaza);
        /// IdTamaño
        wDataBase.AddInParameter(wCmd, "IdTamaño", System.Data.DbType.Int32, pMascotasBE.IdTamaño);
        /// Sexo
        wDataBase.AddInParameter(wCmd, "Sexo", System.Data.DbType.String, pMascotasBE.Sexo);
        /// Edad
        wDataBase.AddInParameter(wCmd, "Edad", System.Data.DbType.String, pMascotasBE.Edad);
        /// IdPropietario
        wDataBase.AddInParameter(wCmd, "IdPropietario", System.Data.DbType.Int32, pMascotasBE.IdPropietario);
        /// Borrado
        wDataBase.AddInParameter(wCmd, "Borrado", System.Data.DbType.String, pMascotasBE.Borrado);

        wDataBase.ExecuteNonQuery(wCmd);
        pMascotasBE.Id = (System.Int32)wDataBase.GetParameterValue(wCmd, "Id");
      }
      catch (Exception ex)
      {
        throw ex;
      }
      finally
      {
        wCmd.Dispose();
        wCmd = null;
        wDataBase = null;
      }
    }/// <summary>
    /// Update
    /// </summary>
    /// <param name="pMascotasBE">MascotasBE</param>
    /// <returns>void</returns>
    /// <Date>2013-05-05T15:02:35</Date>
    /// <Author>Mx23</Author>
    public static void Update(MascotasBE pMascotasBE)
    {
      Database wDataBase = null;
      DbCommand wCmd = null;

      try
      {
        wDataBase = DatabaseFactory.CreateDatabase("cnnPuntoMascotasWeb");
        wCmd = wDataBase.GetStoredProcCommand("Mascotas_u");

        /// Id
        wDataBase.AddInParameter(wCmd, "Id", System.Data.DbType.Int32, pMascotasBE.Id);
        /// Nombre
        wDataBase.AddInParameter(wCmd, "Nombre", System.Data.DbType.String, pMascotasBE.Nombre);
        /// IdRaza
        wDataBase.AddInParameter(wCmd, "IdRaza", System.Data.DbType.Int32, pMascotasBE.IdRaza);
        /// IdTamaño
        wDataBase.AddInParameter(wCmd, "IdTamaño", System.Data.DbType.Int32, pMascotasBE.IdTamaño);
        /// Sexo
        wDataBase.AddInParameter(wCmd, "Sexo", System.Data.DbType.String, pMascotasBE.Sexo);
        /// Edad
        wDataBase.AddInParameter(wCmd, "Edad", System.Data.DbType.String, pMascotasBE.Edad);
        /// IdPropietario
        wDataBase.AddInParameter(wCmd, "IdPropietario", System.Data.DbType.Int32, pMascotasBE.IdPropietario);
        /// Borrado
        wDataBase.AddInParameter(wCmd, "Borrado", System.Data.DbType.String, pMascotasBE.Borrado);

        wDataBase.ExecuteNonQuery(wCmd);

      }
      catch (Exception ex)
      {
        throw ex;
      }
      finally
      {
        wCmd.Dispose();
        wCmd = null;
        wDataBase = null;
      }
    }/// <summary>
    /// Delete
    /// </summary>
    /// <param name="pId">Id</param>
    /// <returns>void</returns>
    /// <Date>2013-05-05T15:02:35</Date>
    /// <Author>Mx23</Author>
    public static void Delete(System.Int32 pId)
    {
      Database wDataBase = null;
      DbCommand wCmd = null;

      try
      {
        wDataBase = DatabaseFactory.CreateDatabase("cnnPuntoMascotasWeb");
        wCmd = wDataBase.GetStoredProcCommand("Mascotas_d");

        /// Id
        wDataBase.AddInParameter(wCmd, "Id", System.Data.DbType.Int32, pId);

        wDataBase.ExecuteNonQuery(wCmd);

      }
      catch (Exception ex)
      {
        throw ex;
      }
      finally
      {
        wCmd.Dispose();
        wCmd = null;
        wDataBase = null;
      }
    }/// <summary>
    /// GetAll
    /// </summary>

    /// <returns>DataSet</returns>
    /// <Date>2013-05-05T15:02:35</Date>
    /// <Author>Mx23</Author>
    public static DataSet GetAll()
    {
      Database wDataBase = null;
      DbCommand wCmd = null;

      try
      {
        wDataBase = DatabaseFactory.CreateDatabase("cnnPuntoMascotasWeb");
        wCmd = wDataBase.GetStoredProcCommand("Mascotas_s");


        return wDataBase.ExecuteDataSet(wCmd);
      }
      catch (Exception ex)
      {
        throw ex;
      }
      finally
      {
        wCmd.Dispose();
        wCmd = null;
        wDataBase = null;
      }
    }/// <summary>
    /// GetByParam
    /// </summary>

    /// <returns>DataSet</returns>
    /// <Date>2013-05-05T15:02:35</Date>
    /// <Author>Mx23</Author>
    public static DataSet GetByParam(MascotasBE pMascotasBE)
    {
      Database wDataBase = null;
      DbCommand wCmd = null;

      try
      {
        wDataBase = DatabaseFactory.CreateDatabase("cnnPuntoMascotasWeb");
        wCmd = wDataBase.GetStoredProcCommand("Mascotas_g");
        
        /// Id
        wDataBase.AddInParameter(wCmd, "Id", System.Data.DbType.Int32, pMascotasBE.Id);
        /// Nombre
        wDataBase.AddInParameter(wCmd, "Nombre", System.Data.DbType.String, pMascotasBE.Nombre);
        /// IdRaza
        wDataBase.AddInParameter(wCmd, "IdRaza", System.Data.DbType.Int32, pMascotasBE.IdRaza);
        /// IdTamaño
        wDataBase.AddInParameter(wCmd, "IdTamaño", System.Data.DbType.Int32, pMascotasBE.IdTamaño);
        /// Sexo
        wDataBase.AddInParameter(wCmd, "Sexo", System.Data.DbType.String, pMascotasBE.Sexo);
        /// Edad
        wDataBase.AddInParameter(wCmd, "Edad", System.Data.DbType.String, pMascotasBE.Edad);
        /// IdPropietario
        wDataBase.AddInParameter(wCmd, "IdPropietario", System.Data.DbType.Int32, pMascotasBE.IdPropietario);
        /// Borrado
        wDataBase.AddInParameter(wCmd, "Borrado", System.Data.DbType.String, pMascotasBE.Borrado);

        return wDataBase.ExecuteDataSet(wCmd);

      }
      catch (Exception ex)
      {
        throw ex;
      }
      finally
      {
        wCmd.Dispose();
        wCmd = null;
        wDataBase = null;
      }
    }
  }
}